package com.liuliu.zua.service.impl;

import java.util.List;
import com.liuliu.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.liuliu.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.liuliu.zua.domain.ZuaRecruit;
import com.liuliu.zua.mapper.ZuaRecruitDetailsMapper;
import com.liuliu.zua.domain.ZuaRecruitDetails;
import com.liuliu.zua.service.IZuaRecruitDetailsService;

/**
 * detailsService业务层处理
 * 
 * @author liuliu
 * @date 2021-04-01
 */
@Service
@SuppressWarnings("all")
public class ZuaRecruitDetailsServiceImpl implements IZuaRecruitDetailsService 
{
    @Autowired
    private ZuaRecruitDetailsMapper zuaRecruitDetailsMapper;

    /**
     * 查询details
     * 
     * @param rDetailsId detailsID
     * @return details
     */
    @Override
    public ZuaRecruitDetails selectZuaRecruitDetailsById(Long rDetailsId)
    {
        return zuaRecruitDetailsMapper.selectZuaRecruitDetailsById(rDetailsId);
    }

    @Override
    public List<ZuaRecruitDetails> getInfoByRecruitId(Long recruitId) {
        return zuaRecruitDetailsMapper.getInfoByRecruitId(recruitId);
    }

    /**
     * 查询details列表
     * 
     * @param zuaRecruitDetails details
     * @return details
     */
    @Override
    public List<ZuaRecruitDetails> selectZuaRecruitDetailsList(ZuaRecruitDetails zuaRecruitDetails)
    {
        return zuaRecruitDetailsMapper.selectZuaRecruitDetailsList(zuaRecruitDetails);
    }

    /**
     * 新增details
     * 
     * @param zuaRecruitDetails details
     * @return 结果
     */
    @Transactional
    @Override
    public int insertZuaRecruitDetails(ZuaRecruitDetails zuaRecruitDetails)
    {
        zuaRecruitDetails.setCreateTime(DateUtils.getNowDate());
        int rows = zuaRecruitDetailsMapper.insertZuaRecruitDetails(zuaRecruitDetails);
        insertZuaRecruit(zuaRecruitDetails);
        return rows;
    }

    /**
     * 修改details
     * 
     * @param zuaRecruitDetails details
     * @return 结果
     */
    @Transactional
    @Override
    public int updateZuaRecruitDetails(ZuaRecruitDetails zuaRecruitDetails)
    {
        zuaRecruitDetails.setUpdateTime(DateUtils.getNowDate());
        zuaRecruitDetailsMapper.deleteZuaRecruitByRecruitId(zuaRecruitDetails.getrDetailsId());
        insertZuaRecruit(zuaRecruitDetails);
        return zuaRecruitDetailsMapper.updateZuaRecruitDetails(zuaRecruitDetails);
    }

    /**
     * 批量删除details
     * 
     * @param rDetailsIds 需要删除的detailsID
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteZuaRecruitDetailsByIds(Long[] rDetailsIds)
    {
        zuaRecruitDetailsMapper.deleteZuaRecruitByRecruitIds(rDetailsIds);
        return zuaRecruitDetailsMapper.deleteZuaRecruitDetailsByIds(rDetailsIds);
    }

    /**
     * 删除details信息
     * 
     * @param rDetailsId detailsID
     * @return 结果
     */
    @Override
    public int deleteZuaRecruitDetailsById(Long rDetailsId)
    {
        zuaRecruitDetailsMapper.deleteZuaRecruitByRecruitId(rDetailsId);
        return zuaRecruitDetailsMapper.deleteZuaRecruitDetailsById(rDetailsId);
    }

    /**
     * 新增${subTable.functionName}信息
     * 
     * @param zuaRecruitDetails details对象
     */
    public void insertZuaRecruit(ZuaRecruitDetails zuaRecruitDetails)
    {
        List<ZuaRecruit> zuaRecruitList = zuaRecruitDetails.getZuaRecruitList();
        Long rDetailsId = zuaRecruitDetails.getrDetailsId();
        if (StringUtils.isNotNull(zuaRecruitList))
        {
            List<ZuaRecruit> list = new ArrayList<ZuaRecruit>();
            for (ZuaRecruit zuaRecruit : zuaRecruitList)
            {
                zuaRecruit.setRecruitId(rDetailsId);
                list.add(zuaRecruit);
            }
            if (list.size() > 0)
            {
                zuaRecruitDetailsMapper.batchZuaRecruit(list);
            }
        }
    }
}
